package com.dou.you.che.web.controller.sys;

import com.dou.you.che.comm.annotation.SysLogI;
import com.dou.you.che.comm.utils.page.PageUtils;
import com.dou.you.che.comm.utils.query.QueryParam;
import com.dou.you.che.comm.utils.response.RspData;
import com.dou.you.che.core.entity.sys.SysScheduleJobLog;
import com.dou.you.che.service.sys.SysScheduleJobLogServiceI;
import com.dou.you.che.web.controller.base.BaseAct;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 定时任务日志
 * @Author 黄国刚【1058118328@qq.com】
 */
@RestController
@RequestMapping(value = "sys/scheduleLog")
public class SysScheduleJobLogAct extends BaseAct {

    @Autowired
    private SysScheduleJobLogServiceI scheduleJobLogService;

    /**
     * 定时任务日志列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:schedule:log")
    @SysLogI("定时任务日志列表")
    public RspData list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        QueryParam query = new QueryParam(params);
        List<SysScheduleJobLog> jobList = scheduleJobLogService.queryList(query);
        int total = scheduleJobLogService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(jobList, total, query.getLimit(), query.getPage());

        return RspData.ok().put("page", pageUtil);
    }

    /**
     * 定时任务日志信息
     */
    @RequestMapping("/info/{logId}")
    @SysLogI("定时任务日志信息")
    public RspData info(@PathVariable("logId") Long logId) {
        SysScheduleJobLog log = scheduleJobLogService.queryObject(logId);

        return RspData.ok().put("log", log);
    }
}
